package com.example.controller;

import com.example.elasticsearch.data.MyDocument;
import com.example.service.MyDocumentSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/my/document/search")
public class MyDocumentSearchController {

    @Autowired
    private MyDocumentSearchService searchService;

    // match 查询
    @GetMapping("/match")
    public List<MyDocument> searchByMatchQuery(@RequestParam String text) {
        return searchService.searchByMatchQuery(text);
    }

    // match_all 查询
    @GetMapping("/matchAll")
    public List<MyDocument> searchByMatchAllQuery() {
        return searchService.searchByMatchAllQuery();
    }

    // term 查询
    @GetMapping("/term")
    public List<MyDocument> searchByTermQuery(@RequestParam String keyword) {
        return searchService.searchByTermQuery(keyword);
    }

    // range 查询
    @GetMapping("/range")
    public List<MyDocument> searchByRangeQuery(@RequestParam int start, @RequestParam int end) {
        return searchService.searchByRangeQuery(start, end);
    }

    // bool 查询
    @GetMapping("/bool")
    public List<MyDocument> searchByBoolQuery(@RequestParam String text, @RequestParam boolean booleanValue) {
        return searchService.searchByBoolQuery(text, booleanValue);
    }

    // wildcard 查询
    @GetMapping("/wildcard")
    public List<MyDocument> searchByWildcardQuery(@RequestParam String pattern) {
        return searchService.searchByWildcardQuery(pattern);
    }

    // prefix 查询
    @GetMapping("/prefix")
    public List<MyDocument> searchByPrefixQuery(@RequestParam String prefix) {
        return searchService.searchByPrefixQuery(prefix);
    }

    // exists 查询
    @GetMapping("/exists")
    public List<MyDocument> searchByExistsQuery(@RequestParam String fieldName) {
        return searchService.searchByExistsQuery(fieldName);
    }
}
